<?php

function dbString($string) {
    $string = htmlentities($string);
    return mysql_real_escape_string($string);
}

function dbReverseString($string) {
    return html_entity_decode($string);
}


function cutTextByWordcount($text, $maxWords) {
    
    $text = explode(' ', $text);
    
    $wordCount = 1;
    $shortenedText = '';
    $maxWordsReached = false;
    
    foreach($text as $word) {
        if($wordCount <= $maxWords) {
            $shortenedText .= ' '.$word;
        } else {
            
            if($maxWordsReached == false) {
                $shortenedText .= ' ......';
                $maxWordsReached = true;
            }
            
        }
        $wordCount++;
    }
    
    return $shortenedText;
    
}

?>
